/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net
 * (C) 2004-2008, Refractions Research Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package symbology;

import java.util.ArrayList;
import feature.*;

/**
 * A RangeSymbolizer picks one of several symbolizers based on a numeric attribute 
 * <p>
 *
 * </p>
 * @author John
 * @since 1.1.0
 */
public class RangeSymbolizer implements Symbolizer {
    
    String attributeName;
    ArrayList<Range> ranges;
    
    /**
     * @param attributeName - the name of the numeric attribute used for selection
     */
    RangeSymbolizer(String attributeName)
    {
        this.attributeName = attributeName;
        ranges = new ArrayList<Range>();
    }
    
    /**
     * add adds another range option to the RangeSymbolizer
     * @param range
     */
    void add(Range range)
    {
        ranges.add(range);
    }
  
    
    
    public void addSymbols( Feature feature, double scale, Symbols symbols ) {
        
        // Get the value for this feature
        double value = feature.getValueAsDouble(attributeName);
   
        
        for (Range r: ranges)
            if (value >= r.min && value <= r.max) {
                r.symbolizer.addSymbols(feature, scale, symbols);
                break;
            }
    }

}
